package sskj.regulatory.presentation.screen.home

import isskj.regulatory.presentation.base_mvp.api.ApiPresenter
import sskj.regulatory.di.scope.PerActivity
import sskj.regulatory.domain.interactor.UserInteractor
import sskj.regulatory.presentation.constans.Constans
import javax.inject.Inject


@PerActivity
class SetupPresenter @Inject constructor()
    : ApiPresenter<SetupContract.View>(), SetupContract.Presenter {

    override fun logOut() {
        view.showLoading()
        run(userInteractor.logOut(), {
            view.hideLoading()
            when (it) {
                true -> view?.logOutOk()
                else -> {
                    view?.showError("注销失败!")
                }
            }
        }, {
            view.hideLoading()
            view?.showError(it.message)
        })
    }

    override fun indexData() {
        fetch(userInteractor.getIndexData()) {
            view.hideLoading()
            view?.setupWithData(it)
        }
    }

    override fun onPresenterCreate() {
        super.onPresenterCreate()
        indexData()
    }


}